let math = require('mathjs')
// 定义一个计算类来计算数据
class computedFunc {
  constructor (transBeforeData) {
    this.transBeforeData = transBeforeData
    // 处理好的数据需要返回的值 ===========all
    this.restur = {
      // 表头数据
      tableLine: [],
      // 总数据处理
      countData: [],
      // 计算次数
      computedNum: 0
    }
    // 处理好的转置数据
    this.transData = []
    // 处理好的图表数据======>折线、柱状图
    this.chartsDatazz = {
      legend: {
        type: 'scroll',
        bottom: 0,
        data: ['蒸发量', '降水量']
        // zlevel: 1
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross'
        }
      },
      calculable: true,
      grid: {
        top: '7%',
        left: '1%',
        bottom: '9%',
        containLabel: true

      },
      xAxis: [{
        type: 'category',
        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
      }],
      yAxis: [{
        type: 'value',
        splitNumber: 4
      }],
      series: [{
        name: '蒸发量',
        type: 'bar',
        data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
      },
      {
        name: '降水量',
        type: 'bar',
        data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
      }
      ]
    }
    // 饼图数据
    this.chartsDatazzPie = {
      // title: {
      //   text: '某站点用户访问来源',
      //   subtext: '纯属虚构',
      //   x: 'center'
      // },
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      legend: {
        type: 'scroll',
        bottom: '0',
        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎', 'jhjgbh', '45445455445']
      },
      series: [{
        name: '访问来源',
        type: 'pie',
        avoidLabelOverlap: true,
        radius: '55%',
        center: ['50%', '50%'],
        data: [{
          value: 335,
          name: '直接访问'
        },
        {
          value: 310,
          name: '邮件营销'
        },
        {
          value: 234,
          name: '联盟广告'
        },
        {
          value: 135,
          name: '视频广告'
        },
        {
          value: 1548,
          name: '搜索引擎'
        },
        {
          value: 15458,
          name: 'jhjgbh'
        },
        {
          value: 15458,
          name: '45445455445'
        }
        ],
        itemStyle: {
          emphasis: {
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }]
    }
    // 选中数据          ==========input
    this.selectData = {
      // 表头数据
      tableLine: [],
      // 总数据处理
      countData: []
    }
  }
  // 初始化所有的数据
  initAllData () {
    // 处理好的数据需要返回的值 ===========all
    this.restur = {
      // 表头数据
      tableLine: [],
      // 总数据处理
      countData: [],
      // 计算次数
      computedNum: 0
    }
    // 处理好的转置数据
    this.transData = []
    // 处理好的图表数据======>折线、柱状图
    this.chartsDatazz = {
      legend: {
        type: 'scroll',
        bottom: 0,
        data: ['蒸发量', '降水量']
        // zlevel: 1
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'cross'
        }
      },
      calculable: true,
      grid: {
        top: '7%',
        left: '1%',
        bottom: '9%',
        containLabel: true

      },
      xAxis: [{
        type: 'category',
        data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
      }],
      yAxis: [{
        type: 'value',
        splitNumber: 4
      }],
      series: [{
        name: '蒸发量',
        type: 'bar',
        data: [2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
      },
      {
        name: '降水量',
        type: 'bar',
        data: [2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3]
      }
      ]
    }
    // 饼图数据
    this.chartsDatazzPie = {
      // title: {
      //   text: '某站点用户访问来源',
      //   subtext: '纯属虚构',
      //   x: 'center'
      // },
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} ({d}%)'
      },
      legend: {
        type: 'scroll',
        bottom: '0',
        data: ['直接访问', '邮件营销', '联盟广告', '视频广告', '搜索引擎', 'jhjgbh', '45445455445']
      },
      series: [{
        name: '访问来源',
        type: 'pie',
        avoidLabelOverlap: true,
        radius: '55%',
        center: ['50%', '50%'],
        data: [{
          value: 335,
          name: '直接访问'
        },
        {
          value: 310,
          name: '邮件营销'
        },
        {
          value: 234,
          name: '联盟广告'
        },
        {
          value: 135,
          name: '视频广告'
        },
        {
          value: 1548,
          name: '搜索引擎'
        },
        {
          value: 15458,
          name: 'jhjgbh'
        },
        {
          value: 15458,
          name: '45445455445'
        }
        ],
        itemStyle: {
          emphasis: {
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }]
    }
    // 选中数据          ==========input
    this.selectData = {
      // 表头数据
      tableLine: [],
      // 总数据处理
      countData: []
    }
  }
  // 处理input选中数据
  inputSelectData (listArr, lineArr) { // listArr 列选中的数组    //line行选中的数组
    // 重定向数组
    let listArrs = JSON.parse(JSON.stringify(listArr))
    let lineArrs = JSON.parse(JSON.stringify(lineArr))
    listArrs.unshift(0) // 必选第一项
    if (this.restur.tableLine.length < listArrs.length) {
      listArrs = this.restur.tableLine.map((item, index) => {
        return index
      })
    }
    if (this.restur.countData.length < lineArrs.length) {
      lineArrs = this.restur.countData.map((item, index) => {
        return index
      })
    }
    // 处理数据显示
    this.selectData.tableLine = []
    console.log(this.restur.tableLine, 'this.restur.tableLine')
    console.log(listArrs, lineArrs)
    listArrs.forEach((items, indexs) => {
      this.selectData.tableLine.push({
        labelId: this.restur.tableLine[items].labelId,
        label: this.restur.tableLine[items].label
      })
    })
    // this.selectData.tableLine = this.restur.tableLine
    let datart = JSON.parse(JSON.stringify(this.restur.countData))
    let csd1 = datart.map((itemCol, indexCol) => {
      let newArr = {}
      Object.keys(itemCol).forEach((itemRow, indexRow) => {
        if (listArrs.indexOf(indexRow) !== -1) {
          newArr[itemRow] = itemCol[itemRow]
        }
      })
      return newArr
    })
    this.selectData.countData = lineArrs.map((lineItem, lineIndex) => {
      return csd1[lineItem]
    })
  }
  // 处理转置数据
  comTransAllData (arr) {
    this.transData = arr[0].map(function (col, index) {
      return arr.map((row, key) => {
        return row[index]
      })
    })
  }
  // 处理行列图表数据
  comRowColAllData (arr) {
    return arr[0].map(function (col, index) {
      return arr.map((row, key) => {
        return row[index]
      })
    })
  }
  // 处理非地区数据转置前的数据，返回可渲染的数据格式
  comTransBefore () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '指标'
    })
    this.transBeforeData.timeArr.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 总数据处理
    this.transBeforeData.termsName.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transBeforeData.transBeforeTermsData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 处理非地区数据转置后的数据，返回可渲染的数据格式
  comTransAfter () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '时间'
    })
    this.transBeforeData.termsName.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 将数据转置
    this.comTransAllData(this.transBeforeData.transBeforeTermsData)
    // 总数据处理
    this.transBeforeData.timeArr.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 处理非地区数据转置后的数据，返回可渲染的数据格式
  comTransAreabefore () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '地区'
    })
    this.transBeforeData.timeArr.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 总数据处理
    this.transBeforeData.areaName.forEach((itemName, indexName) => {
      // console.log(this.transBeforeData.transBeforeAreaData, 'this.transBeforeData.transBeforeAreaData')
      var tableLine = {}
      this.transBeforeData.transBeforeAreaData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 处理地区数据转置后的数据，返回可渲染的数据格式
  comTransAreaAfter () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '时间'
    })
    this.transBeforeData.areaName.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 将数据转置
    // 总数据处理
    this.transBeforeData.timeArr.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transBeforeData.transBeforeAreaData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 地区数据对于维度转化的处理    时间======指标
  comTransAreabeforeTimeLabel () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '时间'
    })
    this.transBeforeData.termsName.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    console.log(this.transBeforeData, 'this.transBeforeData101')
    // 总数据处理
    this.transBeforeData.timeArr.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transBeforeData.transBeforeAreaData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 地区数据对于维度转化的处理    指标======时间
  comTransAreabeforeLabelTime () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '指标'
    })
    this.transBeforeData.timeArr.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 总数据处理
    this.transBeforeData.termsName.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transBeforeData.transBeforeAreaData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 地区数据对于维度转化的处理    地区======指标
  comTransAreabeforeAreaLabel () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '地区'
    })
    this.transBeforeData.termsName.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 总数据处理
    this.transBeforeData.areaName.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transBeforeData.transBeforeAreaData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // 地区数据对于维度转化的处理    指标======地区
  comTransAreabeforeLabelArea () {
    // 表头数据处理
    this.restur.tableLine.push({
      labelId: 'table_line0',
      label: '指标'
    })
    this.transBeforeData.areaName.forEach((itemTime, indexTime) => {
      this.restur.tableLine.push({
        labelId: 'table_line' + (indexTime + 1),
        label: itemTime
      })
    })
    // 总数据处理
    this.transBeforeData.termsName.forEach((itemName, indexName) => {
      var tableLine = {}
      this.transBeforeData.transBeforeAreaData[indexName].forEach((dataList, dataKey) => {
        if (dataKey === 0) {
          tableLine['table_line0'] = itemName
        }
        tableLine['table_line' + (dataKey + 1)] = dataList
      })
      this.restur.countData.push(tableLine)
    })
    return this.restur
  }
  // SUM求和                   ============对行运算
  dataSumLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'SUM求和' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      // console.log(item, 'item002255')
      var arr = Object.values(item)
      arr.shift()
      if (arr.length < 2) {
        arr.push('0')
        arr.push('0')
      }
      console.log(arr, 'arr000')
      return math.add(...arr).toFixed(2)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // SUM求和                   ============对列运算
  dataSumList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.add(...item).toFixed(2)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'SUM求和' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // x平均数                 ========>对行运算
  dataAVGLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'x平均数' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return (math.add(...arr).toFixed(2)) / arr.length
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // x平均数                   ============对列运算
  dataAVGList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return (math.add(...item).toFixed(2)) / item.length
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'x平均数' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // MAX最大值                   ============对行运算
  dataMAXLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'MAX最大值' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return math.max(...arr)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // MAX最大值                   ============对列运算
  dataMAXList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.max(...item)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'MAX最大值' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // MIN最小值                   ============对行运算
  dataMINLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'MIN最小值' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return math.min(...arr)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // MIN最小值                   ============对列运算
  dataMINList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.min(...item)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'MIN最小值' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // MD中位数                   ============对行运算
  dataMDLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'MD中位数' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return math.median(...arr).toFixed(2)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // MD中位数                   ============对列运算
  dataMDList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.median(...item).toFixed(2)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'MD中位数' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // MO众数                   ============对行运算
  dataMOLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'MO众数' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return math.mode(...arr)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // MO众数                   ============对列运算
  dataMOList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.mode(...item)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'MO众数' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // S²方差                   ============对行运算
  dataSSLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'S²方差' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return math.variance(...arr).toFixed(2)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // S²方差                   ============对列运算
  dataSSList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.variance(...item).toFixed(2)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'S²方差' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // S标准差                   ============对行运算
  dataSLine () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    dataRs.tableLine.push({
      label: 'S标准差' + this.restur.computedNum,
      labelId: 'table_line' + dataRs.tableLine.length
    })
    let bth = dataRs.countData.map((item, index) => {
      var arr = Object.values(item)
      arr.shift()
      return math.std(...arr).toFixed(2)
    })
    dataRs.countData.forEach((item, index) => {
      item['table_line' + (dataRs.tableLine.length - 1)] = bth[index]
    })
    this.restur = dataRs
    return this.restur
  }
  // S标准差                   ============对列运算
  dataSList () {
    let dataRs = JSON.parse(JSON.stringify(this.restur))
    // 处理现在的数据
    let datarts = this.restur.countData.map((item, index) => {
      let arrt = Object.values(item)
      arrt.shift()
      return arrt
    })
    // 将数据转置
    this.comTransAllData(datarts)
    let transSum = this.transData.map((item, index) => {
      return math.std(...item).toFixed(2)
    })
    let returObj = {}
    transSum.forEach((item, index) => {
      if (index === 0) {
        returObj['table_line' + index] = 'S标准差' + this.restur.computedNum
      }
      returObj['table_line' + (index + 1)] = item
    })
    dataRs.countData.push(returObj)
    this.restur = dataRs
    return this.restur
  }
  // ========================================================非地区数据
  // 竖状图数据                ============行转换
  dataVerticalMapRow () {
    let termsName = []
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    this.chartsDatazz.series = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return {
        name: keys,
        type: 'bar',
        data: obju
      }
    })
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: termsName
    }
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.xAxis = [{
      type: 'category',
      data: timeArr
    }]
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    return this.chartsDatazz
  }
  // 竖状图数据                ============列转换
  dataVerticalMapCol () {
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    let termsName = []
    let seriess = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return obju
    })
    // 将数据转置
    this.chartsDatazz.series = this.comRowColAllData(seriess).map((item, index) => {
      return {
        name: this.selectData.tableLine[index + 1].label,
        type: 'bar',
        data: item
      }
    })
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: timeArr
    }
    this.chartsDatazz.xAxis = [{
      type: 'category',
      data: termsName
    }]
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    return this.chartsDatazz
  }
  // =========================================================地区数据
  // 竖状图数据                ============行转换   时间===地区
  dataVerticalMapRowAreaSJDQ () {
    let termsName = []
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    this.chartsDatazz.series = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return {
        name: keys,
        type: 'bar',
        data: obju
      }
    })
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: termsName
    }
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.xAxis = [{
      type: 'category',
      data: timeArr
    }]
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    return this.chartsDatazz
  }
  // 竖状图数据                ============列转换   地区===时间
  dataVerticalMapColAreaDQSJ () {
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    let termsName = []
    let seriess = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return obju
    })
    // 将数据转置
    this.chartsDatazz.series = this.comRowColAllData(seriess).map((item, index) => {
      return {
        name: this.selectData.tableLine[index + 1].label,
        type: 'bar',
        data: item
      }
    })
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: timeArr
    }
    this.chartsDatazz.xAxis = [{
      type: 'category',
      data: termsName
    }]
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    return this.chartsDatazz
  }
  // 横状图数据                ============行转换
  dataAcrossMapRow () {
    let termsName = []
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    this.chartsDatazz.series = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return {
        name: keys,
        type: 'bar',
        data: obju
      }
    })
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: termsName
    }
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.xAxis = [{
      type: 'value'

    }]
    this.chartsDatazz.yAxis = [{
      type: 'category',
      data: timeArr
    }]
    return this.chartsDatazz
  }
  // 竖状图数据                ============列转换
  dataAcrossMapCol () {
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    let termsName = []
    let seriess = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return obju
    })
    // 将数据转置
    this.chartsDatazz.series = this.comRowColAllData(seriess).map((item, index) => {
      return {
        name: this.selectData.tableLine[index + 1].label,
        type: 'bar',
        data: item
      }
    })
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: timeArr
    }
    this.chartsDatazz.xAxis = [{
      type: 'value'

    }]
    this.chartsDatazz.yAxis = [{
      type: 'category',
      data: termsName
    }]
    return this.chartsDatazz
  }
  // 折线图数据                ============行转换
  dataBrokenLineMapRow () {
    let termsName = []
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    this.chartsDatazz.series = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return {
        name: keys,
        type: 'line',
        data: obju
      }
    })
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: termsName
    }
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.xAxis = [{
      type: 'category',
      data: timeArr
    }]
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    return this.chartsDatazz
  }
  // 折线图数据                ============列转换
  dataBrokenLineMapCol () {
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    let termsName = []
    let seriess = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      termsName.push(keys)
      return obju
    })
    // 将数据转置
    this.chartsDatazz.series = this.comRowColAllData(seriess).map((item, index) => {
      return {
        name: this.selectData.tableLine[index + 1].label,
        type: 'line',
        data: item
      }
    })
    let timeArr = this.selectData.tableLine.map((item, index) => {
      return item.label
    })
    timeArr.shift()
    this.chartsDatazz.legend = {
      type: 'scroll',
      bottom: 0,
      data: timeArr
    }
    this.chartsDatazz.xAxis = [{
      type: 'category',
      data: termsName
    }]
    this.chartsDatazz.yAxis = [{
      type: 'value',
      splitNumber: 6
    }]
    return this.chartsDatazz
  }
  // 饼图数据                ============行转换
  dataPieMapRow () {
    let termsLine = []
    let cloneLine = JSON.parse(JSON.stringify(this.selectData.tableLine))
    console.log(cloneLine, 'cloneLine')
    cloneLine.forEach((item, index) => {
      if (index !== 0) {
        termsLine.push(item.label)
      }
    })
    this.chartsDatazzPie.legend.data = termsLine

    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    this.chartsDatazzPie.series = cloneSarr.map((item, index) => {
      let obju = Object.values(item)
      let keys = obju.shift()
      return {
        name: keys,
        type: 'pie',
        radius: '55%',
        center: ['40%', '50%'],
        data: obju.map((itemObj, indexObj) => {
          return {
            name: termsLine[indexObj],
            value: itemObj
          }
        }),
        itemStyle: {
          emphasis: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
          }
        }
      }
    })
    console.log(this.chartsDatazzPie)
    return this.chartsDatazzPie
  }
  // 饼图数据                ============列转换
  dataPieMapCol () {
    let cloneLine = JSON.parse(JSON.stringify(this.selectData.tableLine))
    let cloneSarr = JSON.parse(JSON.stringify(this.selectData.countData))
    this.chartsDatazzPie.legend.data = cloneSarr.map((item, index) => {
      return Object.values(item)[0]
    })
    this.chartsDatazzPie.series = {
      name: cloneLine[1].label,
      type: 'pie',
      radius: '55%',
      center: ['40%', '50%'],
      data: cloneSarr.map((itemObj, indexObj) => {
        return {
          name: Object.values(itemObj)[0],
          value: Object.values(itemObj)[1]
        }
      }),
      itemStyle: {
        emphasis: {
          shadowBlur: 10,
          shadowOffsetX: 0,
          shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
      }
    }
    return this.chartsDatazzPie
  }
  // 导出至EXcel tableData:表数据   tableLine：列数据   listInputVal:选中列下标  lineInputVal：选中行下标 ===》对选中的部分导出
  insertCollectS (tableData, tableLine, listInputVal, lineInputVal) {
    // 定义一个对象用来分发数据
    let objData = {
      header: null,
      tableData: null
    }
    let yuan = JSON.parse(JSON.stringify(listInputVal))
    yuan.unshift(0)
    // 除了第一行剩下的行的所有选中的数据
    let shHangData = []
    // 第一行所有选中的数据
    // let hangAllDatas=[]
    // let hangAllDatas = tableLine.filter((item, index) => {
    //   return listInputVal.indexOf(index) !== -1
    // }).map((item, index) => {
    //   return item.label
    // })
    // lastAllData.push(hangAllDatas)
    shHangData = tableData.map((item, index) => {
      // tableData.forEach((list, key) => {
      return Object.values(item).filter((list, key) => {
        return yuan.indexOf(key) !== -1
      })
      // })
    }).filter((item, index) => {
      return lineInputVal.indexOf(index) !== -1
    })
    let hangAllDatas = null
    if (tableLine.length < yuan.length) {
      hangAllDatas = tableLine.map((item, index) => {
        return tableLine[index].label
      })
    } else {
      hangAllDatas = yuan.map((item, index) => {
        return tableLine[item].label
      })
    }

    // shHangData.unshift(hangAllDatas)
    objData.header = hangAllDatas.map((item, index) => {
      return [item, index]
    })
    objData.tableData = shHangData
    // 导出的数据
    return objData
  }
  /*
   * @desc 导出至EXcel（表中有多少数据导出多少数据）
   * @param tableData [Array] 表数据
   * @param tableLine [Array] 列数据
   *
   */
  exportDataAll (tableData, tableLine) {
    // 定义一个对象用来分发数据
    let objData = {
      header: null,
      tableData: null
    }
    // 除了第一行剩下的行的所有选中的数据
    let shHangData = []
    shHangData = tableData.map((item, index) => {
      return Object.values(item)
    })
    let hangAllDatas = null
    hangAllDatas = tableLine.map((item, index) => {
      return tableLine[index].label
    })

    // shHangData.unshift(hangAllDatas)
    objData.header = hangAllDatas.map((item, index) => {
      return [item, index]
    })
    objData.tableData = shHangData
    // 导出的数据
    return objData
  }
}
export default computedFunc
